package com.aitesting.domain;

import cn.hutool.core.bean.BeanUtil;
import org.springframework.util.ReflectionUtils;

import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 用于将TRequest对象转化为Map
 */
public class BaseModel implements Serializable {
    public Map<String, ?> map(){
        Map<String, ?> map1 = Arrays.stream(BeanUtil.getPropertyDescriptors(this.getClass()))
                .filter(item -> !"class".equals(item.getName()))
                .collect(HashMap::new, (map, pd) -> map.put(pd.getName(), ReflectionUtils.invokeMethod(pd.getReadMethod(),this)),
                        HashMap::putAll);

        return map1;
    }
}
